<!doctype html>
<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Nestify</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="icon" type="image/x-icon" href="../images/favicon.ico">
	      <link rel="stylesheet" href="../styles/style.css">
    </head>
    <body>

        <div class="navbar navbar-default navbar-fixed-top visible-xs">
            <a href="../" class="navbar-brand">Nestify</a>
            <button type="button" class="btn btn-default btn-menu ion-ios-menu" id="btn-menu"></button>
        </div>

        <div class="xs-menu menu" id="mobile-menu">
                <div id="book-search-input" role="search"><input type="text" placeholder="请输入查询关键字"></div>            <compodoc-menu></compodoc-menu>
        </div>

        <div class="container-fluid main">
           <div class="row main">
               <div class="hidden-xs menu">
                   <compodoc-menu mode="normal"></compodoc-menu>
               </div>
               <!-- START CONTENT -->
               <div class="content class">
                   <div class="content-data">











<ol class="breadcrumb">
  <li>类列表</li>
  <li>ContextTrace</li>
</ol>

<ul class="nav nav-tabs" role="tablist">
        <li class="active">
            <a href="#info" role="tab" id="info-tab" data-toggle="tab" data-link="info">Info</a>
        </li>
        <li >
            <a href="#source" role="tab" id="source-tab" data-toggle="tab" data-link="source">Source</a>
        </li>
</ul>

<div class="tab-content">
    <div class="tab-pane fade active in" id="c-info">
        <p class="comment">
            <h3>文件</h3>
        </p>
        <p class="comment">
            <code>server/src/common/lib/logger.ts</code>
        </p>





            <section>
    <h3 id="index">索引</h3>
    <table class="table table-sm table-bordered index-table">
        <tbody>
                <tr>
                    <td class="col-md-4">
                        <h6><b>属性列表</b></h6>
                    </td>
                </tr>
                <tr>
                    <td class="col-md-4">
                        <ul class="index-list">
                            <li>
                                    <span class="modifier">Public</span>
                                    <span class="modifier">Readonly</span>
                                    <span class="modifier">可选的</span>
                                <a href="#columnNumber">columnNumber</a>
                            </li>
                            <li>
                                    <span class="modifier">Public</span>
                                    <span class="modifier">Readonly</span>
                                <a href="#context">context</a>
                            </li>
                            <li>
                                    <span class="modifier">Public</span>
                                    <span class="modifier">Readonly</span>
                                    <span class="modifier">可选的</span>
                                <a href="#lineNumber">lineNumber</a>
                            </li>
                            <li>
                                    <span class="modifier">Public</span>
                                    <span class="modifier">Readonly</span>
                                    <span class="modifier">可选的</span>
                                <a href="#path">path</a>
                            </li>
                        </ul>
                    </td>
                </tr>






        </tbody>
    </table>
</section>

            <section>
    <h3 id="constructor">构造方法</h3>
        <table class="table table-sm table-bordered">
            <tbody>
                <tr>
                    <td class="col-md-4">
<code>constructor(context: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>, path?: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>, lineNumber?: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank">number</a>, columnNumber?: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank">number</a>)</code>
                    </td>
                </tr>
                        <tr>
                            <td class="col-md-4">
                                <div class="io-line">被定义在 <a href="" data-line="21" class="link-to-prism">server/src/common/lib/logger.ts:21</a></div>
                            </td>
                        </tr>

                <tr>
                    <td class="col-md-4">
                            <div>
                                    <b>参数列表 :</b>
                                    <table class="params">
                                        <thead>
                                            <tr>
                                                <td>名称</td>
                                                    <td>类型</td>
                                                <td>可选的</td>
                                            </tr>
                                        </thead>
                                        <tbody>
                                                <tr>
                                                        <td>context</td>
                                                  
                                                        <td>
                                                                        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
                                                        </td>
                                                  
                                                    <td>
                                                            否
                                                    </td>
                                                    
                                                </tr>
                                                <tr>
                                                        <td>path</td>
                                                  
                                                        <td>
                                                                        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
                                                        </td>
                                                  
                                                    <td>
                                                            是
                                                    </td>
                                                    
                                                </tr>
                                                <tr>
                                                        <td>lineNumber</td>
                                                  
                                                        <td>
                                                                        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>
                                                        </td>
                                                  
                                                    <td>
                                                            是
                                                    </td>
                                                    
                                                </tr>
                                                <tr>
                                                        <td>columnNumber</td>
                                                  
                                                        <td>
                                                                        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>
                                                        </td>
                                                  
                                                    <td>
                                                            是
                                                    </td>
                                                    
                                                </tr>
                                        </tbody>
                                    </table>
                            </div>
                    </td>
                </tr>
            </tbody>
        </table>
</section>

            <section>
    
        <h3 id="inputs">
            属性列表
        </h3>
        <table class="table table-sm table-bordered">
            <tbody>
                <tr>
                    <td class="col-md-4">
                        <a name="columnNumber"></a>
                        <span class="name">
                            <b>
                                <span class="modifier">Public</span>
                                <span class="modifier">Readonly</span>
                                <span class="modifier">可选的</span>
                            columnNumber</b>
                            <a href="#columnNumber"><span class="icon ion-ios-link"></span></a>
                        </span>
                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                            <i>类型 : </i>        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>

                        </td>
                    </tr>
                        <tr>
                            <td class="col-md-4">
                                    <div class="io-line">被定义在 <a href="" data-line="26" class="link-to-prism">server/src/common/lib/logger.ts:26</a></div>
                            </td>
                        </tr>


            </tbody>
        </table>
        <table class="table table-sm table-bordered">
            <tbody>
                <tr>
                    <td class="col-md-4">
                        <a name="context"></a>
                        <span class="name">
                            <b>
                                <span class="modifier">Public</span>
                                <span class="modifier">Readonly</span>
                            context</b>
                            <a href="#context"><span class="icon ion-ios-link"></span></a>
                        </span>
                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                            <i>类型 : </i>        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>

                        </td>
                    </tr>
                        <tr>
                            <td class="col-md-4">
                                    <div class="io-line">被定义在 <a href="" data-line="23" class="link-to-prism">server/src/common/lib/logger.ts:23</a></div>
                            </td>
                        </tr>


            </tbody>
        </table>
        <table class="table table-sm table-bordered">
            <tbody>
                <tr>
                    <td class="col-md-4">
                        <a name="lineNumber"></a>
                        <span class="name">
                            <b>
                                <span class="modifier">Public</span>
                                <span class="modifier">Readonly</span>
                                <span class="modifier">可选的</span>
                            lineNumber</b>
                            <a href="#lineNumber"><span class="icon ion-ios-link"></span></a>
                        </span>
                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                            <i>类型 : </i>        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>

                        </td>
                    </tr>
                        <tr>
                            <td class="col-md-4">
                                    <div class="io-line">被定义在 <a href="" data-line="25" class="link-to-prism">server/src/common/lib/logger.ts:25</a></div>
                            </td>
                        </tr>


            </tbody>
        </table>
        <table class="table table-sm table-bordered">
            <tbody>
                <tr>
                    <td class="col-md-4">
                        <a name="path"></a>
                        <span class="name">
                            <b>
                                <span class="modifier">Public</span>
                                <span class="modifier">Readonly</span>
                                <span class="modifier">可选的</span>
                            path</b>
                            <a href="#path"><span class="icon ion-ios-link"></span></a>
                        </span>
                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                            <i>类型 : </i>        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>

                        </td>
                    </tr>
                        <tr>
                            <td class="col-md-4">
                                    <div class="io-line">被定义在 <a href="" data-line="24" class="link-to-prism">server/src/common/lib/logger.ts:24</a></div>
                            </td>
                        </tr>


            </tbody>
        </table>
</section>







    </div>


    <div class="tab-pane fade  tab-source-code" id="c-source">
        <pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import * as _ from &#x27;lodash&#x27;;
import * as Path from &#x27;path&#x27;;
import * as Log4js from &#x27;log4js&#x27;;
import * as Util from &#x27;util&#x27;;
import * as Moment from &#x27;moment&#x27;;
import * as StackTrace from &#x27;stacktrace-js&#x27;;
import Chalk from &#x27;chalk&#x27;;

export enum LoggerLevel {
    ALL &#x3D; &#x27;ALL&#x27;,
    MARK &#x3D; &#x27;MARK&#x27;,
    TRACE &#x3D; &#x27;TRACE&#x27;,
    DEBUG &#x3D; &#x27;DEBUG&#x27;,
    INFO &#x3D; &#x27;INFO&#x27;,
    WARN &#x3D; &#x27;WARN&#x27;,
    ERROR &#x3D; &#x27;ERROR&#x27;,
    FATAL &#x3D; &#x27;FATAL&#x27;,
    OFF &#x3D; &#x27;OFF&#x27;
}

export class ContextTrace {
    constructor(
        public readonly context: string,
        public readonly path?: string,
        public readonly lineNumber?: number,
        public readonly columnNumber?: number
    ) {}
}

Log4js.addLayout(&#x27;Nestify&#x27;, (logConfig: any) &#x3D;&gt; {
    return (logEvent: Log4js.LoggingEvent): string &#x3D;&gt; {
        let moduleName: string &#x3D; &#x27;&#x27;;
        let position: string &#x3D; &#x27;&#x27;;

        const messageList: string[] &#x3D; [];
        logEvent.data.forEach((value: any) &#x3D;&gt; {
            if (value instanceof ContextTrace) {
                moduleName &#x3D; value.context;
                if (value.lineNumber &amp;&amp; value.columnNumber) {
                    position &#x3D; &#x60;${value.lineNumber}, ${value.columnNumber}&#x60;;
                }
                return;
            }

            if (typeof value !&#x3D;&#x3D; &#x27;string&#x27;) {
                value &#x3D; Util.inspect(value, false, 3, true);
            }

            messageList.push(value);
        });

        const messageOutput: string &#x3D; messageList.join(&#x27; &#x27;);
        const positionOutput: string &#x3D; position ? &#x60; [${position}]&#x60; : &#x27;&#x27;;
        const typeOutput: string &#x3D; &#x60;[${logConfig.type}] ${logEvent.pid.toString()}   - &#x60;;
        const dateOutput: string &#x3D; &#x60;${Moment(logEvent.startTime).format(&#x27;YYYY-MM-DD HH:mm:ss&#x27;)}&#x60;;
        const moduleOutput: string &#x3D; moduleName ? &#x60;[${moduleName}] &#x60; : &#x27;[LoggerService] &#x27;;
        let levelOutput: string &#x3D; &#x60;[${logEvent.level}] ${messageOutput}&#x60;;

        switch (logEvent.level.toString()) {
            case LoggerLevel.DEBUG:
                levelOutput &#x3D; Chalk.green(levelOutput);
                break;
            case LoggerLevel.INFO:
                levelOutput &#x3D; Chalk.cyan(levelOutput);
                break;
            case LoggerLevel.WARN:
                levelOutput &#x3D; Chalk.yellow(levelOutput);
                break;
            case LoggerLevel.ERROR:
                levelOutput &#x3D; Chalk.red(levelOutput);
                break;
            case LoggerLevel.FATAL:
                levelOutput &#x3D; Chalk.hex(&#x27;#DD4C35&#x27;)(levelOutput);
                break;
            default:
                levelOutput &#x3D; Chalk.grey(levelOutput);
                break;
        }

        return &#x60;${Chalk.green(typeOutput)}${dateOutput}    ${Chalk.yellow(
            moduleOutput
        )}${levelOutput}${positionOutput}&#x60;;
    };
});

Log4js.configure({
    appenders: {
        console: {
            type: &#x27;stdout&#x27;,
            layout: { type: &#x27;Nestify&#x27; }
        }
    },
    categories: {
        default: {
            appenders: [&#x27;console&#x27;],
            level: &#x27;debug&#x27;
        }
    }
});

const logger &#x3D; Log4js.getLogger();
logger.level &#x3D; &#x27;debug&#x27;;

export class Logger {
    static trace(...args) {
        logger.trace(Logger.getStackTrace(), ...args);
    }

    static debug(...args) {
        logger.debug(Logger.getStackTrace(), ...args);
    }

    static log(...args) {
        logger.info(Logger.getStackTrace(), ...args);
    }

    static info(...args) {
        logger.info(Logger.getStackTrace(), ...args);
    }

    static warn(...args) {
        logger.warn(Logger.getStackTrace(), ...args);
    }

    static warning(...args) {
        logger.warn(Logger.getStackTrace(), ...args);
    }

    static error(...args) {
        logger.error(Logger.getStackTrace(), ...args);
    }

    static fatal(...args) {
        logger.fatal(Logger.getStackTrace(), ...args);
    }

    static getStackTrace(deep: number &#x3D; 2): ContextTrace {
        const stackList: StackTrace.StackFrame[] &#x3D; StackTrace.getSync();
        const stackInfo: StackTrace.StackFrame &#x3D; stackList[deep];

        const lineNumber: number &#x3D; stackInfo.lineNumber;
        const columnNumber: number &#x3D; stackInfo.columnNumber;
        const fileName: string &#x3D; stackInfo.fileName;

        const extnameLength: number &#x3D; Path.extname(fileName).length;
        let basename: string &#x3D; Path.basename(fileName);
        basename &#x3D; basename.substr(0, basename.length - extnameLength);
        const context: string &#x3D; _.upperFirst(_.camelCase(basename));

        return new ContextTrace(context, fileName, lineNumber, columnNumber);
    }

    trace(...args) {
        logger.trace(Logger.getStackTrace(), ...args);
    }

    debug(...args) {
        logger.debug(Logger.getStackTrace(), ...args);
    }

    log(...args) {
        logger.info(Logger.getStackTrace(), ...args);
    }

    info(...args) {
        logger.info(Logger.getStackTrace(), ...args);
    }

    warn(...args) {
        logger.warn(Logger.getStackTrace(), ...args);
    }

    warning(...args) {
        logger.warn(Logger.getStackTrace(), ...args);
    }

    error(...args) {
        logger.error(Logger.getStackTrace(), ...args);
    }

    fatal(...args) {
        logger.fatal(Logger.getStackTrace(), ...args);
    }
}
</code></pre>
    </div>
</div>







                   </div><div class="search-results">
    <div class="has-results">
        <h1 class="search-results-title"><span class='search-results-count'></span> result-matching "<span class='search-query'></span>"</h1>
        <ul class="search-results-list"></ul>
    </div>
    <div class="no-results">
        <h1 class="search-results-title">无匹配的结果 "<span class='search-query'></span>"</h1>
    </div>
</div>
</div>
               <!-- END CONTENT -->
           </div>
       </div>

       <script>
            var COMPODOC_CURRENT_PAGE_DEPTH = 1;
            var COMPODOC_CURRENT_PAGE_CONTEXT = 'class';
            var COMPODOC_CURRENT_PAGE_URL = 'ContextTrace.html';
       </script>

       <script src="../js/libs/custom-elements.min.js"></script>
       <script src="../js/libs/lit-html.js"></script>
       <!-- Required to polyfill modern browsers as code is ES5 for IE... -->
       <script src="../js/libs/custom-elements-es5-adapter.js" charset="utf-8" defer></script>
       <script src="../js/menu-wc.js" defer></script>

       <script src="../js/libs/bootstrap-native.js"></script>

       <script src="../js/libs/es6-shim.min.js"></script>
       <script src="../js/libs/EventDispatcher.js"></script>
       <script src="../js/libs/promise.min.js"></script>
       <script src="../js/libs/zepto.min.js"></script>

       <script src="../js/compodoc.js"></script>

       <script src="../js/tabs.js"></script>
       <script src="../js/menu.js"></script>
       <script src="../js/libs/clipboard.min.js"></script>
       <script src="../js/libs/prism.js"></script>
       <script src="../js/sourceCode.js"></script>
          <script src="../js/search/search.js"></script>
          <script src="../js/search/lunr.min.js"></script>
          <script src="../js/search/search-lunr.js"></script>
          <script src="../js/search/search_index.js"></script>
       <script src="../js/lazy-load-graphs.js"></script>


    </body>
</html>
